﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Business.WEB;
using Presenters.WEB;
using Presenters.WEB.Views;

namespace AirlinePilotAcademy_WPF
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window, ILoginView
    {
        LoginPresenter presenter;
        bool allowedToLogin { get; set; }


        public MainWindow()
        {
            InitializeComponent();
            presenter = new LoginPresenter(this);
        }
        public string username
        {
            get { return usernameTB.Text; }
        }
        public string password
        {
            get { return passwordTB.Password; }
        }
        public string Message
        {
            set { messageL.Content = value; }
        }
        public bool userExits
        {
            set { allowedToLogin = value; }
        }
        private void CancelB_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void LoginB_Click(object sender, RoutedEventArgs e)
        {
            presenter.SubmitLogin();
            allowedToLogin = presenter.userExists;
            if (allowedToLogin)
            {
                string tipo = UserTypeManager.GetUserType(usernameTB.Text);
                if (tipo == "Administrator")
                {
                    MainWidow_AdminMenu adminM = new MainWidow_AdminMenu();
                    adminM.ShowDialog();
                }
                if(tipo == "Secretary")
                {
                    MainWindow_SecreMenu secreM = new MainWindow_SecreMenu();
                    secreM.ShowDialog();
                }
                EraseTB();
                presenter = new LoginPresenter(this);
            }
        }
        private void EraseTB()
        {
            this.messageL.Content = "";
            this.usernameTB.Text = "";
            this.passwordTB.Password = "";
        }
        private void CommandBinding_CanExecute_1(object sender, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = false;
            e.Handled = true;
        }

        private void CommandBinding_CanExecute_2(object sender, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = false;
            e.Handled = true;
        }
        
    }
}
